package com.springboot.onlinemusicserver.utils.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-18
 * Time: 19:12
 */
@Data
public class Result<T> {
    private ResultCodeEnum resultCodeEnum;
    private String message;
    private T data;


    private Result() {

    }

    private Result(ResultCodeEnum resultCodeEnum, String message, T data) {
        this.resultCodeEnum = resultCodeEnum;
        this.message = message;
        this.data = data;
    }

    // 业务处理成功
    public static <T> Result<T> success() {
        return new Result<>(ResultCodeEnum.SUCCESS, "", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultCodeEnum.SUCCESS, "", data);
    }

    // 业务处理失败
    public static <T> Result<T> error(String message) {
        return new Result<>(ResultCodeEnum.ERROR, message, null);
    }

    public static <T> Result<T> error(String message, T data) {
        return new Result<>(ResultCodeEnum.ERROR, message, data);
    }

    // 系统异常
    public static <T> Result<T> fatal(String message) {
        return new Result<>(ResultCodeEnum.FATAL, message, null);
    }
}
